Conventions for Sample Code
The sample code presented throughout this book follows a number of conventions to help you understand the code and to distinguish application-defined routines from system software routines. For the most part, the sample code listings presented throughout the Inside Macintosh suite of books follow these conventions as well.
- Constants defined by the Venn Diagrammer application begin with the letter
k
. For example, the number of tools in a Venn diagram window is specified by the constantkNumTools
. There are, however, several exceptions to this rule:
- Constants specifying resource IDs begin with the letter
r
. For example, the resource ID of the menu bar is specified by the constantrMenuBar
.- Constants specifying menu resource IDs begin with the letter
m
. For example, the resource ID of the File menu is specified by the constantmFile
.- Constants specifying menu commands begin with the letter
i
. For example, the number of the Quit command in the File menu is specified by the constantiQuit
.- Constants specifying messages displayed to the user in a window's status area begin with the letter
e
. For example, the message "The argument is valid." is specified by the constanteArgIsValid
.
- Application global variables have names beginning with the letter
g
. For example, the global variable that indicates whether the user wants to quit the application is calledgDone
. There are no exceptions to this rule.- Application-defined routines have names beginning with either the prefix
Do
or the prefixMy
. For example, the routine that handles window updating is calledDoUpdate
. Similarly, the routine that returns a random number is calledMyRandom
. There is one exception to this rule:
- Application-defined routines that return Boolean values have names beginning with the prefix
Is
. For example, the routine that determines whether a window is a dialog box is calledIsDialogWindow
. Several system software routines have similar-sounding names. (For instance, the Dialog Manager provides theIsDialogEvent
routine.)
- Application-defined data structures and types have names beginning with the prefix
My
. For example, the structure that holds information about a document window is calledMyDocRec
. A pointer to a record of typeMyDocRec
is of typeMyDocRecPtr
.- Routine parameters and local variables have names beginning with the prefix
my
. For example, many of the routines in the Venn Diagrammer application require a window pointer as one of the parameters; this parameter is usually calledmyWindow
. This convention has, however, many exceptions.
It's worth mentioning in advance that Venn Diagrammer takes a minimalist approach to error-handling: it tries to detect any errors that might adversely affect its further processing and to work around those errors in such a way as to avoid those adverse effects. In fact, this strategy is far too simple for most applications. Your application should provide far more extensive error detection and reporting to the user. See "Handling Errors" beginning on page 176 for some further discussion of error-handling techniques.
- IMPORTANT
- These naming conventions are adopted in this book (and elsewhere in Inside Macintosh) solely for reasons of consistency and clarity. They might not be suitable for your purposes.
![]()